package protocol

import (
	"fmt"
	"net"
)

var PORTS []string = make([]string, 3, 5)

func udpMain() {
	udp_adrr, err := net.ResolveUDPAddr("udp", "127.0.0.1:"+PORTS[0])
	if err != nil {
		fmt.Println("UDP套接字创建失败，", err)
		return
	}
	conn, err := net.ListenUDP("udp", udp_adrr)
	defer conn.Close()

	buf := make([]byte, 1024)

	dataLength, raddr, err := conn.ReadFromUDP(buf)
	if err != nil {
		fmt.Println("获取UDP数据失败，", err)
		return
	}
	fmt.Println("Get data: ", string(buf[:dataLength]))
	conn.WriteToUDP([]byte("I have got Data!"), raddr)

}
